package ca.etsmtl.log320;

import java.util.Arrays;

public class BoardHash {
	
	public long[] mBoard = new long[2];
	public int mProfondeur = 0;
		
	public BoardHash(int[][] board) {
		for (int i = 0; i < board.length; i++) {
			for(int j=0; j<8; j++) {
				mBoard[0] <<= 1;
				mBoard[1] <<= 1;
				
				switch(board[i][j]) {
					case Consts.CASE_BLANC:
						mBoard[0] |= 1;
						break;
					case Consts.CASE_NOIR:
						mBoard[1] |= 1;		
				}
			}
		}
	}
	
	public BoardHash(long[] bitBoard) {
		mBoard[0] = bitBoard[0];
		mBoard[1] = bitBoard[1];
	}

	
	public BoardHash(long[] bitBoard, int profondeur) {
		mBoard[0] = bitBoard[0];
		mBoard[1] = bitBoard[1];
		mProfondeur = profondeur;
	}

	@Override
	public boolean equals(Object obj) {
		BoardHash comp = (BoardHash)obj;
		boolean pEqual = comp.mProfondeur == mProfondeur;
		if(pEqual) {
			boolean bEqual = mBoard[0] == comp.mBoard[0];
			if(bEqual)
				return mBoard[1] == comp.mBoard[1];
			return false;
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return (int) (((mBoard[0] | mBoard[1]) << 3) | mProfondeur) % 2147483647;
	}

	public BoardHash setProfondeur(int i) {
		mProfondeur = i;
		return this;
	}

}
